﻿@model WaiGaoQiaoWeb.Models.StockVM
@{
    ViewBag.Title = "AddStorage";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section Head
{
    @Html.Css("dp")
    @Html.Js("datepicker")
    
    <script type="text/javascript">
        $(document).ready(function () {

            $("#StorageDt1").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
           
            $("form").makeValidationInline();
            //用户输入物品名称 带出这个物品的别的信息
            $("#Article_ID").bind("change", function () {
                if ($("#Article_ID").val() != 0) {
                    $.post('@Url.Action("RtnStorageInfoForUnit","Storage")', { "Id": $("#Article_ID").val() }, function (data) {

                        $("#Article_No").val(data.ArticleNO);
                        $("#Article_Color").val(data.Color);
                        TtnUnitList(data.ArticleUnit, data.ArticleUnitId);
                      
                    });

                }

            });
            function TtnUnitList(ArticleUnit, ArticleUnitId) {
                $("#Article_Unit").children("option").remove();
                $("<option value='0' selected=selected>请选择... </option>").appendTo($("#Article_Unit"));
                if (ArticleUnit != null && ArticleUnit != "") {
                    var charUnit = ArticleUnit.split(',');
                    var charUnitId = ArticleUnitId.split(',');
                    if (charUnit.length > 0) {
                        for (var i = 0; i < charUnitId.length; i++) {
                            $("<option value=" + charUnitId[i] + ">" + charUnit[i] + " </option>").appendTo($("#Article_Unit"));
                        }
                    } //if
                } //if
            } //end
            //保存
            $("#btnSave").click(function (event) {
             

                if (!$("#fmEdit").valid()) {
                    return false;
                }
                $('#fmEdit').ajaxSubmit(function (callback) {
                    if (callback) {
//                        $(":input").each(function () {
//                            if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
//                                $(this).val("");
//                            }
//                        });
//                        $("#Article_No").focus();
                        refresh();
                    }
                });
            }); // end of btnSave

            //关闭
            $("#btnCancel").click(function (e) {
                $(":input").each(function () {
                    if ($(this).attr("type") == "text" || $(this).attr("type") == "textarea") {
                        $(this).val("");
                    }
                });
                $("#Article_No").focus();
                if ($("#ID").val() != "0") {
                    CloseModelWindow(null, true);
                    return false;
                }
                if (parent) {
                    for (var i = 0; i < parent.document.frames.length; i++) {
                        if (parent.document.frames[i].document.getElementById("orderno")) {
                            parent.document.frames[i].document.getElementById("orderno").value = $("#OrderNo").val();
                        }
                    }
                    CloseModelWindow(null, true);
                }
            });
            var option = {
                height: 220,
                width: 740,
                url: '@Url.Action("GetStorageDetailListByOrderNo")',
                colModel: [
                    { display: '编号', name: 'ID', width: 60, sortable: false, align: 'left', hide: true, iskey: true },
                     { display: '入库日期', name: 'StorageDt', width: 80, sortable: false, hide: false, align: 'left' },
			         { display: '物资名称', name: 'Article_ID', width: 120, sortable: false, hide: false, align: 'left' },
                     { display: '颜色', name: 'Article_Color', width: 80, sortable: false, hide: false, align: 'left' },
                     { display: '规格/型号', name: 'Article_Unit', width: 80, sortable: false, hide: false, align: 'left' },
                     { display: '数量', name: 'Count', width: 80, sortable: false, hide: false, align: 'left' },
                     { display: '供应商', name: 'Supplier', width: 120, sortable: false, hide: false, align: 'left' },
                     { display: '备注', name: 'Remark', width: 260, sortable: false, hide: false, align: 'left' },
                     { display: '记录日期', name: 'RecordDateTime', width: 120, sortable: false, hide: true, align: 'left' },
                     { display: '操作人', name: 'OperatorID', width: 120, sortable: false, hide: true, align: 'left' }
				],
                singleselected: true,
                sortname: "Sequence",
                sortorder: "asc",
                title: false,
                usepager: true,
                page: 1,
                rp: 15,
                rpOptions: [10, 15],
                showcheckbox: true,
                rowbinddata: true,
                query: $("#OrderNo").val()
            };
            var grid = $("#StoryTemp").flexigrid(option);
            $("#btnDel").click(function () {
                var items = $(grid).getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的行!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除吗？")) {
                    return false;
                }
                for (var i = 0; i < items.length; i++) {
                    var id = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("Delete")',
                        data: { id: id },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                $("#StoryTemp").flexOptions(option).flexReload();
                            }
                        },
                        error: function () { }
                    });   // end of ajax                    
                }
            });
            function refresh() {
                showLoadingMsg("保存成功", { left: 400, top: 6 }, true, 3000);
                $("#StoryTemp").flexOptions(option).flexReload();
            }
        });
    </script>
}
@using (Html.BeginForm("SaveStoryDetail", "Storage", FormMethod.Post, new { id = "fmEdit" }))
{
    @Html.ValidationSummary(true)
    <div class="mainpanel">
        @Html.HiddenFor(model => model.ID)
        @Html.HiddenFor(model => model.OrderNo)
        @Html.HiddenFor(model=>model.RecordDateTime)
        @Html.HiddenFor(model=>model.OperatorID)
        <table style="width:100%; width:740px;">
        <tr>
        <td colspan="4">&nbsp;</td>
        </tr>
            <tr>
                <td style="text-align:right;">@Html.LabelFor(model => model.StorageDt1)</td>
                <td>@Html.TextBoxFor(model => model.StorageDt1, new { @style = "width:145px;", @ReadOnly = true })
                    @Html.ValidationMessageFor(model => model.StorageDt1)<span style="color:Red;">*</span></td>
               <td style="text-align:right;">@Html.LabelFor(model => model.Article_ID)</td>
                <td>
				  @Html.DropDownListFor(model => model.Article_ID, ViewBag.ArticleList as IEnumerable<SelectListItem>, new { @style="width:155px"})
			      @Html.ValidationMessageFor(model => model.Article_ID)<span style="color:Red;">*</span></td>
            </tr>
            <tr>
                <td style="text-align:right;">@Html.LabelFor(model => model.Article_Unit)</td>
                <td> 
                 @Html.DropDownListFor(model=>model.Article_Unit, ViewBag.UnitList as IEnumerable<SelectListItem>, new { @style = "width:155px;height:20px;" })
                  </td>
                <td style="text-align:right;">@Html.LabelFor(model => model.Count)</td>
                <td>@Html.TextBoxFor(model => model.Count)
                    @Html.ValidationMessageFor(model => model.Count)</td>
            </tr>
            <tr>
             <td style="text-align:right;">@Html.LabelFor(model => model.Article_No)</td>
                <td>@Html.TextBoxFor(model=>model.Article_No)
                               </td>
               
                <td style="text-align:right;">@Html.LabelFor(model => model.Supplier)</td>
                <td>
                 @Html.DropDownListFor(model => model.Supplier, ViewBag.SupplierList as IEnumerable<SelectListItem>, new { @style = "width:155px;height:20px;" })
                    @Html.ValidationMessageFor(model => model.Supplier)</td>
            </tr>
            <tr>
                <td style="text-align:right;">@Html.LabelFor(model => model.Article_Color)</td>
                <td>
				@Html.TextBoxFor(model => model.Article_Color)
			    </td>
               
                <td style="text-align:right;">@Html.LabelFor(model => model.Remark)</td>
                <td >@Html.TextBoxFor(model => model.Remark)
                    @Html.ValidationMessageFor(model => model.Remark)</td>
            </tr>
          
            <tr>
                <td></td>
                <td></td>
                <td colspan="2" style="text-align:right;">
                    <a id="btnSave" class="button" href="javascript:void(0);"><span>保 存</span></a> 
                    <a id="btnDel" class="button" href="javascript:void(0);"><span>删 除</span></a>
                    <a id="btnCancel" class="button" href="javascript:void(0);"><span>关 闭</span></a>
                </td>
            </tr>
        </table>
        <div style="width:740px; overflow-x:scroll;">
            <table id="StoryTemp" style="display: none;"></table>
        </div>
    </div>
}



